/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Sep 8, 2009 12:26:51 AM $
 *
 * Author: Eric Yang
 * Date  : Sep 8, 2009 12:26:51 AM
 *
 */
package com.gooex.domain.base;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.gooex.domain.company.Company;

/**
 * 订单供应商
 * 
 * @author Eric Yang
 * @version 1.0
 */
public class OrderVendor implements Serializable {

	/** PK */
	private String id;

	/** 对应供应商公司 */
	private Company company;

	/** 对应订单 */
	private Order order;

	/** 客户为此供应商投票数 */
	private int voteCount = 0;

	/** 对此订单的相关说明,比如优惠信息 */
	private String declaration;

	/** 供应商针对每个客户的报价 */
	private List<OrderQuote> orderQuotes = new ArrayList<OrderQuote>();

	/** 客户对此供应商的投票信息 */
	private List<Evaluation> evaluations = new ArrayList<Evaluation>();

	private Map<OrderRequest, OrderQuote> quoteMap;

	/* =============functions============================================ */
	public Map<OrderRequest, OrderQuote> getQuoteMap() {
		if (quoteMap == null) {
			quoteMap = new HashMap<OrderRequest, OrderQuote>();
			for (int i = 0; i < orderQuotes.size(); i++) {
				OrderQuote quote = orderQuotes.get(i);
				quoteMap.put(quote.getOrderRequest(), quote);
			}
		}
		return quoteMap;
	}

	/* =============setters/getters============================================ */
	public List<Evaluation> getEvaluations() {
		return evaluations;
	}

	public void setEvaluations(List<Evaluation> evaluations) {
		this.evaluations = evaluations;
	}

	/* ===========functions============================= */
	public void addOrderQuote(OrderQuote orderQuote) {
		if (!orderQuotes.contains(orderQuote))
			orderQuotes.add(orderQuote);
	}

	public void removeOrderQuote(OrderQuote orderQuote) {
		if (orderQuotes.contains(orderQuote))
			orderQuotes.remove(orderQuote);
	}

	/**
	 * 是否所对所有的订单请求都已经报价了 TODO CHECK -- the perfermance maybe not good
	 */
	public boolean hasAllQuote() {
		for (int i = 0; i < orderQuotes.size(); i++) {
			if (!orderQuotes.get(i).hasQuoted())
				return false;
		}
		return true;
	}

	/* ===========setter/getter============================= */
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public List<OrderQuote> getOrderQuotes() {
		return orderQuotes;
	}

	public void setOrderQuotes(List<OrderQuote> orderQuotes) {
		this.orderQuotes = orderQuotes;
	}

	public int getVoteCount() {
		return voteCount;
	}

	public void setVoteCount(int voteCount) {
		this.voteCount = voteCount;
	}

	public String getDeclaration() {
		return declaration;
	}

	public void setDeclaration(String declaration) {
		this.declaration = declaration;
	}
}
